/*
 * @Author: Zhang Aishan 
 * @Date: 2021-07-02 17:21:40 
 * @Last Modified by: Henglin Zhu
 * @Last Modified time: 2021-07-15 18:10:31
 */


<template>
  <view class="successful" :style="{ marginTop: barHeight }">
    <top-bar
      :title="'已完成'"
      :bgColor="'#ffffff'"
      :titleColor="'#000000'"
      @btnClick="returnPage"
    />
    <Successful
      @onLeftBtnClick="onLeftBtnClick"
      @onRightBtnClick="onRightBtnClick"
      :scanBtn="true"
      :sLbtn="true"
      :sRbtn="isr"
      @onScan="onScan"
    >
      <view slot="subTips"> 医学观察登记 </view>
      <view slot="leftBtnText">{{ leftButton }}</view>
      <view slot="rightBtnText">{{ isSelectRoom ? "" : "扫描" }}下一个</view>
    </Successful>
  </view>
</template>

<script>
import Successful from "@/components/Successful.vue";
import TopBar from "../../components/TopBar.vue";
import { scanCode } from "@/utils";
export default {
  components: {
    Successful,
    TopBar,
  },

  data() {
    return {
      isr: true,
      leftButton: "",
      isSelectRoom: "",
      barHeight: "",
      isSelectRoom: "",
    };
  },
  onLoad(options) {
    let { isSelectRoom } = this.$store.state;
    this.isSelectRoom = isSelectRoom;
    this.leftButton = isSelectRoom ? "选择其他房间" : "回到首页";
    this.isChange = options.isChange;
    this.leftButton = this.isChange == "1" ? "返回" : this.leftButton;
    this.isr = this.isChange == "1" ? false : true;
    //设置marginTop
    uni.getSystemInfo({
      success: (res) => {
        this.barHeight = `${res.statusBarHeight}px`;
      },
    });
    function addZ(num) {
      if (num < 10) {
        return (num = "0" + num);
      } else {
        return num;
      }
    }
    var date = new Date();
    var year = date.getFullYear();
    var month = addZ(date.getMonth() + 1);
    var day = addZ(date.getDate());
    var hour = addZ(date.getHours());
    var minutes = addZ(date.getMinutes());
    var second = addZ(date.getSeconds());
    this.curYear = year + "-" + month + "-" + day;
    this.curTime = hour + ":" + minutes + ":" + second;
  },
  methods: {
    onLeftBtnClick() {
      if (this.isChange == "1") {
        uni.navigateBack({
          delta: 3,
        });
        return;
      }
      if (this.isSelectRoom) {
        this.$store.commit("PERSON_DETAIL", []);
        uni.reLaunch({
          url: "../publicRooms/index?type=medicalObservation",
        });
      } else {
        uni.switchTab({
          url: `../index/index`,
        });
      }
    },
    onRightBtnClick() {
      // 如果是选房流程。 判断还有没有人 ，有人就下一个，没人就回房间
      console.log("isSelectRoom", this.isSelectRoom);
      if (this.isSelectRoom) {
        this.$store.commit("FINISH_CHECK");
        if (this.$store.state.personDetail.length !== 0) {
          let nextOne = this.$store.state.personDetail[0];
          this.$store.commit("PERSON_ID", [nextOne.personId]);
          uni.setStorage({ key: "personInfo", data: nextOne });
          uni.reLaunch({
            url: "../medicalObservation/index",
          });
        } else {
          if (this.isSelectRoom) {
            uni.showToast({
              title: "该房间已观察完",
              duration: 2000,
              icon: "none",
              success: () => {
                uni.reLaunch({
                  url: "../publicRooms/index?type=medicalObservation",
                });
              },
            });
          }
        }
      } else {
        scanCode({
          fn: (data) => {
            let personState = data.targetUser.personInfo.personState;
            if(personState == 12 || personState == 21 || personState == 22){
              // 待入住、已入住
              uni.reLaunch({
                url: "../medicalObservation/index",
              });
            }else{
              uni.showToast({
                title: `人员未入住，无法进行此操作！`,
                icon: 'none',
                duration: 3000
              });
            }
          },
        });
      }
    },
    returnPage() {
      this.$store.commit("PERSON_DETAIL", []);
      uni.switchTab({
        url: `../index/index`,
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.successful {
  padding-top: 76rpx;
}
</style>